package com.ktjy.service;

import com.ktjy.entity.SysUser;
import com.ktjy.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/9  8:38
 */
@Service("sysUserService")
//@Transactional ：添加到类上面说明对该类的所有方法都适用
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public List<SysUser> getSysUserList(SysUser sysUser) {
        return sysUserMapper.getSysUserList(sysUser);
    }

    @Transactional
    @Override
    public int saveBatch(List<SysUser> sysUserList) {
        int rows=0;
        for (int i = 0; i <sysUserList.size() ; i++) {
            SysUser sysUser=sysUserList.get(i);
            if (i==1){
                throw new RuntimeException("数据库报错");
            }
            rows=sysUserMapper.insert(sysUser);
        }
        return rows;
    }
}
